<?php
class Files extends Controller {

	function Files()
	{
		parent::Controller();
		$this->users->check();
		$this->load->helper('file');
	}

	function index()
	{
		$data['files'] = get_filenames('files');
		$template['content'] = $this->load->view('files', $data, TRUE);
		if (empty($data['files'])) {
			$data['notice'] = 'No files';
		}	
		$this->load->view('template', $template);
		$template['title'] = 'Files';
	}
	function delete() {
		$file = 'files/' . $this->uri->segment(3);
		unlink($file);
		redirect('files');
	}
	function deleteall() {
		//Deletes all files
		delete_files('files');
		redirect('files');
	}
	function do_upload() 
	{
		$config['upload_path'] = './files/';
		$config['allowed_types'] = 'ppt|jpg|png|gif|psd|xcf|mov|zip|gz|bz|tar|doc|txt|rtf|php|html|xml|rb|rxml|odt|fla|py|sql|exe|msi|mp3|wmv|wma|ogg|mp4|xhtml|phps|dll|dat|csv|pdf|tar.gz';
		$config['max_size']	= '10000';
		$config['max_width']  = '6000';
		$config['max_height']  = '6000';
		$this->load->library('upload', $config);
		$field_name = "file";
		$thread = $_POST['thread'];
		if ( ! $this->upload->do_upload($field_name))
		{
			$error = array('error' => $this->upload->display_errors());
			$error['files'] = get_filenames('files');
			$template['content'] = $this->load->view('files', $error, TRUE);
		$this->load->view('template', $template);
		}	
		else
		{
			$image = $this->upload->data();
			$filename = $image['file_name'];
			$data['hello'] = $hello;

			redirect('files');
		}
	}
}
?> 